<?php

namespace App\Http\Middleware;

use App\Models\User;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;

class CheckWechatLogin
{
    /**
     * 验证小程序端是否微信登陆
     * Handle an incoming request.
     *
     * @param  Request  $request
     * @param  Closure $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!$request->input('api_token') || !User::where('api_token',$request->input('api_token'))->first()) {
            return Response::json([
                'status_code'   =>  401,
                'message'       =>  '请先登录',
                'errors'        =>  ['login'=>'请先登录']
            ]);
        }
        return $next($request);
    }
}
